<?php
/**
 * GioCMS
 * 
 * LICENSE
 *
 * This source file is subject to the GNU GENERAL PUBLIC LICENSE Version 2 
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://www.gnu.org/licenses/gpl-2.0.txt
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@ninhgio.com so we can send you a copy immediately.
 * 
 * @copyright	Copyright (c) 2010-2011 GioCMS (http://cms.ninhgio.com)
 * @license		http://www.gnu.org/licenses/gpl-2.0.txt GNU GENERAL PUBLIC LICENSE Version 2
 * @author		NinhGio - ninhgio@gmail.com
 * @since		1.0
 * @version		$Id:$
 */

$this->headTitle($this->TRANSLATOR->translator('template_list_page_title') . ' - ' . $this->TRANSLATOR->translator('common_admin_title'));
?>
<div class="content">
	<div class="box header mb0">
		<div class="head"><div></div></div>
		<h2 class="g_a_breadcump">
			<a class="fl" href="<?php echo $this->url('core_dashboard_index'); ?>"><?php echo $this->TRANSLATOR->translator('dashboard_breadcump'); ?></a>
			<small class="icon arrow_right" style="display: block;"></small>
			<a class="fl" href="<?php echo $this->url('core_template_list'); ?>"><?php echo $this->TRANSLATOR->translator('template_breadcump'); ?></a>
			<small class="icon arrow_right" style="display: block;"></small>
			<a class="fl" href="javascript: void(0);"><?php echo $this->TRANSLATOR->translator('template_list_breadcump'); ?></a>
			<div class="clear"></div>
		</h2>
	</div>
</div>
<div class="content">
	<div class="desc">
		<div class="body">
			<h4 class="fl g_a_h4"><?php echo $this->TRANSLATOR->translator('template_list_guide'); ?></h4>
			<div class="fr">
				<a class="fl g_a_tip g_a_cancel_button mr5" href="javascript: history.go(-1);" title="<?php echo $this->STRING->escape($this->TRANSLATOR->translator('common_back_button', 'core')); ?>"></a>
			</div>
			<div class="g_a_line"></div>
			<!--  -->
			<table class="g_a_data_table">
				<tbody>
					<tr>
						<th class="checkbox w_1"><input type="checkbox" name="checkbox"></th>
						<th><?php echo $this->TRANSLATOR->translator('template_name'); ?></th>
						<th class="w_12"><?php echo $this->TRANSLATOR->translator('template_author'); ?></th>
						<th class="w_12"><?php echo $this->TRANSLATOR->translator('template_email'); ?></th>
						<th class="w_12"><?php echo $this->TRANSLATOR->translator('template_version'); ?></th>
						<th class="w_12"><?php echo $this->TRANSLATOR->translator('template_status'); ?></th>
					</tr>
					<?php if (isset($this->templates) && $this->templates) : ?>
					<?php foreach ($this->templates as $index => $template) : ?>
					<tr class="g_a_row<?php if ($this->currentTemplate == $template) : ?> g_a_row_affected<?php endif; ?>" id="gCoreTemplateRow_<?php echo $template; ?>">
						<td class="checkbox w_1"><input type="checkbox" name="checkbox"></td>
						<td>
							<div class="content"><strong><?php echo $template; ?></strong></div>
							<div class="g_a_actions buttons_demo">
								<?php if ($this->ACL->isAllowed('list', 'page')) : ?>
								<a class="button yellow" href="<?php echo $this->url('core_page_list', array('template_id' => $template)); ?>"><small class="icon word_documents"></small><span><?php echo $this->TRANSLATOR->translator('page_actions_list'); ?></span></a>
								<?php endif; ?>
								<?php if ($this->ACL->isAllowed('set', 'template') && $this->currentTemplate != $template) : ?>
								<a href="javascript: void(0);" rel="set_<?php echo $template; ?>" class="button green g_a_actions_template">
									<small class="icon check"></small><span><?php echo $this->TRANSLATOR->translator('template_actions_set'); ?></span>
								</a>
								<?php endif; ?>
								<div class="clear"></div>
							</div>
						</td>
						<td class="w_12">&nbsp;</td>
						<td class="w_12">&nbsp;</td>
						<td class="w_12">&nbsp;</td>
						<td class="w_12 g_a_template_status" id="gCoreTemplateRowStatus_<?php echo $template; ?>">
							<?php if ($this->currentTemplate == $template) : ?>
								<b><?php echo $this->TRANSLATOR->translator('template_status_in_use'); ?></b>
							<?php endif; ?>
						</td>
					</tr>
					<?php endforeach; ?>
					<?php endif; ?>
				</tbody>
			</table>
			<!--  -->
			<?php if (isset($this->pager)) : ?>	
			<!-- Pager -->
			<div class="module pagination g_a_pager">
				<?php echo $this->pager->links; ?>
			</div>
			<!-- / Pager -->
			<?php endif; ?>	
		</div>
	</div>
	<div class="body_footer">
		<div class="bottom_left"><div class="bottom_right"></div></div>
	</div>
</div>
<script type="text/javascript">
'Gio.Core.Template'.namespace();
Gio.Core.Template.currenAction = null;
Gio.Core.Template.actions = function(params) {
	/**
	 * Show g_a_ajax_loading element
	 */
	$('#g_a_ajax_loading').show();
	$.ajaxq('core_template_action', {
		type: 'post',
		url: params.url,
		data: params,
		success: function(response) {
			if (response == 'RESULT_OK') {
				var type = 'success';
				$('.g_a_row_affected').removeClass('g_a_row_affected');
				$('#gCoreTemplateRow_' + params.template_id).addClass('g_a_row_affected');
				switch (params.act) {
					case 'set':
						$(Gio.Core.Template.currenAction).remove();
						var message = '<?php echo $this->STRING->escape($this->TRANSLATOR->translator('template_actions_set_success')); ?>';
						$('.g_a_template_status').html('');
						$('#gCoreTemplateRowStatus_' + params.template_id).html('<b><?php echo $this->TRANSLATOR->translator('template_status_in_use'); ?></b>');
						break;
				}
				Gio.Message.success(message);
			} else {
				Gio.Message.error('<?php echo $this->STRING->escape($this->TRANSLATOR->translator('common_error_message')); ?>');
			}
			/**
			 * Hide g_a_ajax_loading element
			 */
			$('#g_a_ajax_loading').hide();
		}
	});
};

$(document).ready(function() {
	$('.g_a_actions_template').each(function() {
		var self = this;
		$(self).bind('click', function() {
			Gio.Core.Template.currenAction = this;
			var stringId = $(this).attr('rel');
			var temp = stringId.split('_');
			var act = temp[0];
			var template = temp[1];
			var url = ''; 
			switch (act) {
				case 'set':
					url = '<?php echo $this->url('core_template_set'); ?>';
					var messsage_confirm = '<?php echo $this->STRING->escape($this->TRANSLATOR->translator('template_actions_set_confirm')); ?>';
					break;
			}
			data = { url: url, template_id: template, act: act };
			Gio.Message.yesButton = '<?php echo $this->STRING->escape($this->TRANSLATOR->translator('common_yes_button', 'core')); ?>';
			Gio.Message.noButton = '<?php echo $this->STRING->escape($this->TRANSLATOR->translator('common_no_button', 'core')); ?>';
			Gio.Message.confirm(messsage_confirm, 'Gio.Core.Template.actions', data);
		});
	});
});
</script>